﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using CardInChina.Bussiness.Frontend.Models;

namespace CardInChina.Web.Mvc
{
    public class ActionInvoker
    {
        public static ActionResult Invoke(ActionExecutingContext context,HttpContext current)
        {
            object result = context.ActionDescriptor.Execute(context.Controller.ControllerContext, context.ActionParameters);
            return CreateActionResult(context.Controller.ControllerContext, context.ActionDescriptor, result);
        }

        private static ActionResult CreateActionResult(ControllerContext controllerContext, ActionDescriptor actionDescriptor, object actionReturnValue)
        {
            if (actionReturnValue == null)
            {
                return new EmptyResult();
            }

            ActionResult actionResult = (actionReturnValue as ActionResult) ??
                new ContentResult { Content = Convert.ToString(actionReturnValue, CultureInfo.InvariantCulture) };
            return actionResult;
        }

    }
}